package com.mall.db.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mall.db.mapper.PmsSkuStockMapper;
import com.mall.pojo.PmsSkuStock;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class PmsSkuStockApiAmpl implements PmsSkuStockApi {
    @Autowired
    private PmsSkuStockMapper pmsSkuStockMapper;

    //批量更新sku库存信息
    @Override
    public void update(Integer pid, PmsSkuStock pmsSkuStock) {
        LambdaQueryWrapper<PmsSkuStock> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(PmsSkuStock::getProductId, pid);
        pmsSkuStockMapper.update(pmsSkuStock, wrapper);
    }

    //根据商品ID及sku编码模糊搜索sku库存
    @Override
    public PmsSkuStock selectById(Integer pid, String keyword) {
        LambdaQueryWrapper<PmsSkuStock> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(keyword != null, PmsSkuStock::getSkuCode, keyword);
        wrapper.eq(PmsSkuStock::getProductId, pid);
        return pmsSkuStockMapper.selectOne(wrapper);
    }

    //创建商品(八接口之一)
    @Override
    public void create(List<PmsSkuStock> pmsSkuStockList) {
        if (pmsSkuStockList != null) {
            for (PmsSkuStock pmsSkuStock : pmsSkuStockList) {
                pmsSkuStockMapper.insert(pmsSkuStock);
            }
        }
    }

    //更新商品 更新八张表之一
    @Override
    public void updates(List<PmsSkuStock> pmsSkuStockList) {
        if (pmsSkuStockList != null) {
            for (PmsSkuStock pmsSkuStock : pmsSkuStockList) {
                pmsSkuStockMapper.updateById(pmsSkuStock);
            }
        }
    }

    @Override
    public List<PmsSkuStock> SelectById(Integer id) {
        LambdaQueryWrapper<PmsSkuStock> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(PmsSkuStock::getProductId, id);
        return pmsSkuStockMapper.selectList(wrapper);
    }


}
